<template>
  <div>
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>
    <el-card class="box-card">
      <el-row>
        <el-col :span="6">
          <el-input placeholder="请输入内容" class="input-with-select">
            <el-button slot="append" icon="el-icon-search"></el-button>
          </el-input>
        </el-col>
      </el-row>

      <el-table :data="tableData" height="620" border style="width: 100%">
        <el-table-column type="index"> </el-table-column>
        <el-table-column prop="order_number" label="订单编号">
        </el-table-column>
        <el-table-column prop="order_price" label="订单价格" width="150">
        </el-table-column>
        <el-table-column prop="pay_status" label="是否付款" width="100">
          <template slot-scope="scope">
            <el-tag type="success" v-if="scope.row.pay_status == '1'"
              >已付款</el-tag
            >
            <el-tag type="danger" v-else>未付款</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="is_send" label="是否发货" width="100">
        </el-table-column>
        <el-table-column prop="create_time" label="下单时间" width="200">
          <template slot-scope="scope">
            {{ scope.row.create_time | dataFormat }}
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button
              type="primary"
              size="small"
              icon="el-icon-edit"
              @click="editAddress"
            ></el-button>
            <el-button
              type="success"
              size="small"
              icon="el-icon-location-outline"
              @click="wl"
            ></el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="pageIndex"
        :page-sizes="pageSizes"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </el-card>
    <!-- 修改地址对话框 -->
    <el-dialog
      title="修改地址"
      :visible.sync="centerDialogVisible"
      width="30%"
      @close="closeDialog"
    >
      <el-form
        :model="addressForm"
        :rules="rules"
        ref="ruleForm"
        label-width="100px"
        class="demo-ruleForm"
      >
        <el-form-item label="省/市" prop="address1">
          <el-cascader
            v-model="addressForm.address1"
            :options="options"
            @change="handleChange"
          ></el-cascader>
        </el-form-item>
        <el-form-item label="详细地址" prop="address2">
          <el-input v-model="addressForm.address2"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="centerDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="centerDialogVisible = false"
          >确 定</el-button
        >
      </span>
    </el-dialog>
    <!-- 物流对话框 -->
    <el-dialog
      title="查看物流"
      :visible.sync="wlDialogVisible"
      width="50%"
      @close="closeDialog"
    >
      <div class="radio">
        排序：
        <el-radio-group v-model="reverse">
          <el-radio :label="true">倒序</el-radio>
          <el-radio :label="false">正序</el-radio>
        </el-radio-group>
      </div>

      <el-timeline :reverse="reverse">
        <el-timeline-item
          v-for="(activity, index) in activities"
          :key="index"
          :timestamp="activity.timestamp"
        >
          {{ activity.content }}
        </el-timeline-item>
      </el-timeline>
      <span slot="footer" class="dialog-footer">
        <el-button @click="wlDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="wlDialogVisible = false"
          >确 定</el-button
        >
      </span>
    </el-dialog>
  </div>
</template>
<script>
import { regionData } from "element-china-area-data";
export default {
  data() {
    return {
      pageIndex: 1,
      pageSize: 10,
      pageSizes: [10, 30, 50],
      total: 0,
      tableData: [],
      centerDialogVisible: false,
      addressForm: {
        address1: [],
        address2: "",
      },
      rules: {
        address1: [{ required: true, message: "请输入省/市", trigger: "blur" }],
        address2: [
          { required: true, message: "请输入详细地址", trigger: "blur" },
          {
            min: 3,
            max: 20,
            message: "长度在 3 到 20 个字符",
            trigger: "blur",
          },
        ],
      },
      options: regionData,
      wlDialogVisible: false,
       reverse: true,
        activities: [{
          content: '活动按期开始',
          timestamp: '2018-04-15'
        }, {
          content: '通过审核',
          timestamp: '2018-04-13'
        }, {
          content: '创建成功',
          timestamp: '2018-04-11'
        }]
    };
  },
  created() {
    this.getOrders();
  },
  methods: {
    async getOrders() {
      const { data: res } = await this.$http.get("orders", {
        params: {
          pagenum: this.pageIndex,
          pagesize: this.pageSize,
        },
      });
      if (res.meta.status != 200) {
        return (this.$message.erro = "获取订单管理列表失败");
      }
      this.tableData = res.data.goods;
      this.total = res.data.total;
    },
    handleSizeChange(val) {
      this.pageSize = val;
      this.getOrders();
    },
    handleCurrentChange(val) {
      this.pageIndex = val;
      this.getOrders();
    },
    editAddress() {
      this.centerDialogVisible = true;
    },
    handleChange(val) {
      console.log(val);
    },
    closeDialog() {
      this.$refs.ruleForm.resetFields();
    },
    async wl() {
      this.wlDialogVisible = true;
      let dh = 1106975712662;
      const { data: res } = await this.$http.get("/kuaidi/" + dh);
      if (res.meta.status != 200) {
        return (this.$message.erro = "获取物流失败");
      }
      console.log(res);
    },
  },
  filters: {
    dataFormat(shijianchuo) {
      function add0(val) {
        return val < 10 ? "0" + val : val;
      }
      var time = new Date(shijianchuo);
      var y = time.getFullYear();
      var m = time.getMonth() + 1;
      var d = time.getDate();
      var h = time.getHours();
      var mm = time.getMinutes();
      var s = time.getSeconds();
      return (
        y +
        "-" +
        add0(m) +
        "-" +
        add0(d) +
        " " +
        add0(h) +
        ":" +
        add0(mm) +
        ":" +
        add0(s)
      );
    },
  },
};
</script>
<style scoped>
</style>